/*
 * Copyright (c) 2006-2022, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2022-05-03     BruceOu      first implementation
 * 2025-08-28     community    add DMA multi-channel support
 */

#ifndef __DRV_ADC_H__
#define __DRV_ADC_H__

#include <rthw.h>
#include <rtthread.h>
#include <board.h>
#include "drv_gpio.h"

#ifdef __cplusplus
extern "C" {
#endif

/* gd32 adc dirver class */

#ifndef ADC_DMA_BUF_LEN
#define ADC_DMA_BUF_LEN   64   /* 必须是通道数的整数倍 */
#endif

struct gd32_adc
{
    uint32_t            adc_periph;
    rcu_periph_enum     adc_clk;
    rt_base_t           adc_pins[16];
    struct rt_adc_device *adc;
    char               *device_name;

#ifdef RT_USING_ADC_DMA
    rt_int8_t           dma_channels[16];
    rt_uint8_t          dma_channel_num;
    rt_uint32_t         dma_buffer[ADC_DMA_BUF_LEN];
    rt_bool_t           dma_enable;

    rcu_periph_enum     dma_periph_clock;
    uint32_t            dma_periph;
    dma_channel_enum    dma_channel;
#endif
};

#ifdef __cplusplus
}
#endif

#endif /* __DRV_ADC_H__ */